package org.lagou;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.rpc.RpcContext;
import org.lagou.bean.ConsumerComponet;
import org.lagou.service.HelloService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @author junbao
 */
public class XmlConsumerMain {

    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
        // 获取消费者组件
        HelloService helloService = context.getBean(HelloService.class);
        while (true) {
            System.in.read();
            try {
                String hello = helloService.sayHello("world!", 100);
                System.out.println(hello);
                // 使用Future来获取结果
                Future<Object> future = RpcContext.getContext().getFuture();
                System.out.println("future hello:" + future.get());
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }

    }

}
